#1 数据类型转换函数
print('非空字符串的布尔值：', bool('hello'))  # True
print('空字符串的布尔值：', bool(''))        # False
print('空列表的布尔值：', bool([]))         # False
print('空列表的布尔值：', bool(list()))     # False
print('空元组的布尔值：', bool(()))         # False
print('空元组的布尔值：', bool(tuple()))    # False
print('空集合的布尔值：', bool(set()))      # False
print('空字典的布尔值：', bool({}))         # False
print('空字典的布尔值：', bool(dict()))     # False
print('非0数值型的布尔值：', bool(123))     # True
print('整数0的布尔值：', bool(0)   )       # False
print('浮点数0.0的布尔值：', bool(0.0))     # False
print('-'*50)
str1 = '98.7'
print(float(str1))
#print(int(str1))   #报错
print('-'*50)

#2 数学函数
print('绝对值：', abs(100), abs(-100), abs(0))
print('商和余数：', divmod(13, 4))
print('最大值：', max('hello'), max([10, 4, 56, 78, 4]))
print('最小值：', min('hello'), min([10, 4, 56, 78, 4]))
print('求和：', sum([10, 4, 56, 78, 4]))
print('x的y次幂：', pow(2, 3))
print(round(3.6))   # 四舍五入 4
print(round(3.1415926, 2))  # 3.14
print(round(315, -1))       # 320
print('-'*50)

#3 迭代器操作函数
# sorted
lst1 = [54, 56, 88, 4, 324, 34]
new_lst1 = sorted(lst1, reverse=True)
print(new_lst1)
print('-'*50)

# reversed
new1_lst1 = reversed(new_lst1)
print(type(new1_lst1))  # <class 'list_reverseiterator'>
print(list(new1_lst1))
print('-'*50)

# zip
lst2 = ['a', 'b', 'c', 'd']
lst3 = [10, 13, 54, 11, 56]
new_lst2 = zip(lst2, lst3)
print(type(new_lst2))   # <class 'zip'>
print(list(new_lst2))
print('-'*50)

# enumerate
enum = enumerate(lst3, start=11)
print(type(enum))   # <class 'enumerate'>
print(list(enum))
print('-'*50)

# all, any
print(all(lst3))    # True
lst4 = [10, 20, '', 30]
print(all(lst4))    # False

print(any(lst4))    # True
lst5 = ['', (), 0]
print(any(lst5))    # False
print('-'*50)

# next
new_lst2 = zip(lst2, lst3)
print(next(new_lst2))
print(next(new_lst2))
print(next(new_lst2))
print('-'*50)

# filter指定条件筛选
def fun(n):
    return n % 2 == 1
lst6 = filter(fun, range(10)) # (fun后不加括号，不是调用）。将range(10)：0-9的整数，都执行一次fun操作
print(list(lst6))
print('-'*50)

# map
def upper1(x):
    return x.upper()
lst7 = ['hello', 'wolrd', 'python']
new_lst7 = map(upper1, lst7)
print(list(new_lst7))
print('-'*50)

#4 其他函数
